package com.ruoyi.project.xkx.order.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.xkx.order.domain.YsOrder;

import com.ruoyi.project.xkx.order.service.YsOrderService;
import com.ruoyi.project.xkx.school.domain.XkxCourse;
import com.ruoyi.project.xkx.school.service.IXkxCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WuYalong
 * @since 2021-05-10
 */
@Api(tags = "预收订单管理")
@RestController
@RequestMapping("/ys-order")
public class YsOrderController {

    @Autowired
    private YsOrderService ysOrderService;

    @Autowired
    private IXkxCourseService iXkxCourseService;
    @ApiOperation("查询所有预售订单数据")
    @GetMapping("/list/{current}/{limit}")
    public AjaxResult getList(@PathVariable Integer current, @PathVariable Integer limit,String orderNumber){
        Page<YsOrder> result = ysOrderService.getListByPage(new Page<YsOrder>(current,limit),orderNumber);
        return AjaxResult.success("ok",result);
    }


    @ApiOperation("新增（生成）订单")
    @PostMapping
    public AjaxResult addNewOrderAndGenerateDetails(@RequestBody YsOrder ysOrder){
        boolean result = ysOrderService.addNewOrderAndGenerateDetails(ysOrder);
        return AjaxResult.success("订单创建成功！",result);
    }

    /**
     * 根据CourseId 获取课程信息
     * @param courseId
     * @return
     */
    @ApiOperation("获取课程信息")
    @GetMapping("/getCourseByCourseId/{courseId}")
    public AjaxResult getCourseByCourseId(@PathVariable Integer courseId){
        XkxCourse result = iXkxCourseService.selectXkxCourseById(courseId);
        return AjaxResult.success(result);
    }
}
